home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_509 / multi_player / sources / umain.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  179 lines

  1. /*      _main.c         Copyright (C) 1985  Lattice, Inc.       */
  2.  
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <ios1.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <workbench/startup.h>
  9. #include <libraries/dos.h>
  10. #include <libraries/dosextens.h>
  11. #include <proto/dos.h>
  12. #include <proto/exec.h>
  13.  
  14. #define MAXARG 32              /* maximum command line arguments */
  15. #define QUOTE  '"'
  16. #define ESCAPE '*'
  17. #define ESC '\027'
  18. #define NL '\n'
  19.  
  20. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  21.  
  22. #ifndef TINY
  23. extern int _fmode,_iomode;
  24. extern int (*_ONBREAK)();
  25. extern int CXBRK();
  26. #endif
  27.  
  28. extern struct UFB _ufbs[];
  29. static int argc;                       /* arg count */
  30. static char **targv, *argv[MAXARG];     /* arg pointers */
  31. static void badarg(char *program);
  32.  
  33. #define MAXWINDOW 40
  34. extern struct WBStartup *WBenchMsg;
  35. /**
  36. *
  37. * name         _main - process command line, open files, and call "main"
  38. *
  39. * synopsis     _main(line);
  40. *              char *line;     ptr to command line that caused execution
  41. *
  42. * description   This function performs the standard pre-processing for
  43. *               the main module of a C program.  It accepts a command
  44. *               line of the form
  45. *
  46. *                       pgmname arg1 arg2 ...
  47. *
  48. *               and builds a list of pointers to each argument.  The first
  49. *               pointer is to the program name.  For some environments, the
  50. *               standard I/O files are also opened, using file names that
  51. *               were set up by the OS interface module XCMAIN.
  52. *
  53. **/
  54. void _main(line)
  55. register char *line;
  56. {
  57.    register char **pargv;
  58.    register int x;
  59. /*
  60.    struct Process *process;
  61.    struct FileHandle *handle;
  62.    static char window[MAXWINDOW+18];
  63. */
  64.     char *argbuf;
  65.  
  66. /*
  67. *
  68. * Build argument pointer list
  69. *
  70. */
  71.    
  72.    while (argc < MAXARG)
  73.    {
  74.         while (isspace(*line))  line++;
  75.         if (*line == '\0')      break;
  76.         pargv = &argv[argc++];
  77.         if (*line == QUOTE)
  78.         {
  79.             argbuf = *pargv = ++line;  /* ptr inside quoted string */
  80.                 while (*line != QUOTE)
  81.                 {
  82.                    if (*line == ESCAPE)
  83.                     {
  84.                           line++;
  85.                         switch (*line)
  86.                         {
  87.                             case 'E':
  88.                                 *argbuf++ = ESC;
  89.                                 break;
  90.                             case 'N':
  91.                                 *argbuf++ = NL;
  92.                                 break;
  93.                             default:
  94.                                 *argbuf++ = *line;
  95.                         }
  96.                         line++;
  97.                     }
  98.                    else
  99.                    {
  100.                      *argbuf++ = *line++;
  101.                    }
  102.               }
  103.               line++;
  104.               *argbuf++ = '\0';    /* terminate arg */
  105.         }
  106.         else            /* non-quoted arg */
  107.         {       
  108.             *pargv = line;
  109.             while ((*line != '\0') && (!isspace(*line))) line++;
  110.             if (*line == '\0')  break;
  111.             else                *line++ = '\0';  /* terminate arg */
  112.         }
  113.    }  /* while */
  114.    targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
  115.  
  116.  
  117. /*
  118. *
  119. * Open standard files
  120. *
  121. */
  122. #ifndef TINY
  123.  
  124.    if (argc == 0)          /* running under workbench      */
  125.    {
  126. /*
  127.         strcpy(window, "con:10/10/320/80/");
  128.         strncat(window, WBenchMsg->sm_ArgList->wa_Name,MAXWINDOW);
  129.         _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  130.         _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  131.         _ufbs[1].ufbflg = UFB_NC;
  132.         _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  133.         _ufbs[2].ufbflg = UFB_NC;
  134.         handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  135.         process = (struct Process *)FindTask(0);
  136.         process->pr_ConsoleTask = (APTR)handle->fh_Type;
  137. */
  138.         x = 0;
  139.    }
  140.    else                    /* running under CLI            */
  141.    {
  142.         _ufbs[0].ufbfh = Input();
  143.         _ufbs[1].ufbfh = Output();
  144.         _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  145.         x = UFB_NC;                     /* do not close CLI defaults    */
  146.  
  147.        _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  148.        _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  149.        _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  150.  
  151.        x = (_fmode) ? 0 : _IOXLAT;
  152.        stdin->_file = 0;
  153.        stdin->_flag = _IOREAD | x;   
  154.        stdout->_file = 1;
  155.        stdout->_flag = _IOWRT | x;
  156.        stderr->_file = 2;
  157.        stderr->_flag = _IORW | x;
  158.  
  159.     /*      establish control-c handler */
  160.  
  161.     _ONBREAK = CXBRK;
  162.    }
  163.  
  164. #endif
  165.  
  166. /*
  167. *
  168. * Call user's main program
  169. *
  170. */
  171.  
  172.    main(argc,targv);              /* call main function */
  173. #ifndef TINY
  174.    exit(0);
  175. #else
  176. _  exit(0);
  177. #endif
  178. }
  179.